<?php
class App_Tpl_Form_Field_File extends App_Tpl_Form_Field{

	public function PreparePost($fieldPostData, $params)
	{
		$fieldPostData = preg_replace(array('#^' . preg_quote(_ROOT_URL) . '#is', '#^' . preg_quote(_ROOT_URL_STATIC) . '#is'), '', urldecode($fieldPostData));
		
		$outValue = array();
		if (is_file(_ROOT_PATH . $fieldPostData))
		{
			$outValue = array('file' => $fieldPostData , 'filesize' => filesize(_ROOT_PATH . $fieldPostData));
		}
		
		return $outValue;
	}

	public function PrepareOut($fieldData, $params)
	{
		$fieldData = (array)$fieldData;
		$fieldData = array(
                                'file' => $fieldData['file'] ? _ROOT_URL_STATIC. (string)$fieldData['file'] : '',
                                'filesize' => (int)$fieldData['filesize'],
		);
		
		return $fieldData;
	}
	
    protected function RenderField()
    {
    	return $this->render('form/field/_file.phtml');
    }
	
}